{
  "properties" : { },
  "id" : "copy1741181264326d20775",
  "script" : null,
  "groupId" : "98b0445b7653484aa929aa88f56cb7a8",
  "name" : "执行对话(混元)",
  "createTime" : 1741019539814,
  "updateTime" : 1741367987692,
  "lock" : null,
  "createBy" : null,
  "updateBy" : null,
  "path" : "doChatHuanYuan",
  "description" : null,
  "returnType" : null,
  "mappingPath" : null,
  "parameters" : [ {
    "name" : "body",
    "value" : null,
    "description" : "请求的参数",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "userId",
    "value" : null,
    "description" : "用户id",
    "required" : false,
    "dataType" : "String",
    "type" : "java.lang.Number",
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ]
}
================================
import cn.dev33.satoken.stp.StpUtil
import log
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import java.time.LocalDateTime;
import '@/ai/huanYuan' as huanYuan

//发送给智能体的内容
// var sendContent = ""
// if (body.sence_pid == 3) {
//     sendContent = "我们是热恋的情侣，我想用" + body.sence_name + "风格。"
// } else {
//     sendContent = body.sence_p_name + "-" body.sence_name
// }
// if (body.type = 1) { //回答
//     sendContent = sendContent + "怎么回答对方的话。对方原话：" + body.content
// } else if (body.type = 2) {
//     sendContent = sendContent + "怎么问对方：" + body.content
// } else {
//     sendContent = sendContent + "对这种话怎么回答：" + body.content
// }

var sendContent = "【" + body.sence_name + "风格】" + body.content

log.info("sendContent value-->" + sendContent);

var insertId = db.table("chat_record").insert({
    userId,
    type: body.type,
    sence_pid: body.sence_pid,
    sence_id: body.sence_id,
    content: body.content,
    lastContent: sendContent,
    createBy: userId,
    createDate: now(),
})


//请求混元
// let result = coze(sendContent)
var result = huanYuan(sendContent)

log.info("result-->" + result)
if (result != null) {
    db.table("chat_record").primary("id").update({
        id: insertId,
        ai_status: "completed", //更新状态
        ai_result: result
    })
    //如果用户是免费用户
    var subscri = db.table("subscription").where().eq("user_id", userId).eq("package_id", 1).selectOne()
    if (subscri != null) {
        //扣减余额表
        var credit = db.table("credit").where().eq("user_id", userId).eq("package_id", 1).selectOne()
        if (credit != null) {
            if (credit.remainCount::int > 0) {
                db.table("credit").primary("id").update({
                    id: credit.id,
                    remainCount: credit.remainCount::int - 1
                })
            }
        }
    }
    return result

}